package com.douguo.recipe.manager;

import com.douguo.recipe.network.Constant;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;

public class SharedPreferencesManager {
	private Context mContext;
	private SharedPreferences mPreferences;
	
	//先init再使用
	public void init(Context context) {
		mContext = context;
		mPreferences = mContext.getSharedPreferences(Constant.PREFERENCES_NAME, Context.MODE_PRIVATE);
		initPreferences();
	}
	
	private void initPreferences() {
		boolean isInit =  getBoolean(Constant.PREFERENCES_KEY_HASINIT);
		if(isInit == false) {
			putBoolean(Constant.PREFERENCES_KEY_USENETWORK,true);
			putBoolean(Constant.PREFERENCES_KEY_DOWNLOADTHUMBNARIL,true);
			putBoolean(Constant.PREFERENCES_KEY_DOWNLOADIMAGE,true);
			putBoolean(Constant.PREFERENCES_KEY_HASINIT,true);
		}
	}
	
	
	public void putBoolean(String key,boolean value) {
		mPreferences.edit()
			.putBoolean(key, value)
			.commit();
	}
	
	public boolean getBoolean(String key) {
		return mPreferences.getBoolean(key, false);
	}
	
	
}
